var e = require;
var t = module;
var o = exports;
var n;
Object.defineProperty(o, "__esModule", {value: !0}), (o.NodeAction = void 0);
var r = e("Privacy"),
    s = e("AdUtils"),
    c = e("EncryptUtil"),
    l = e("TreasureChest"),
    d = e("TreasureChestBox"),
    u = e("UIGetCoinBox"),
    p = e("Banner"),
    h = e("Interstitial"),
    f = e("NativeAdComponent"),
    _ = e("VivoAd"),
    y = ["LQ2021@888@666", "LQ2023jk#vb@Lop", "LQ2023jk#vb@Lop"],
    m = cc._decorator,
    g = m.ccclass;
m.property,
    (function (e) {
        (e[(e.GAME_LOADING_IN_MAIN_UI = 1)] = "GAME_LOADING_IN_MAIN_UI"),
            (e[(e.GAME_ENTER_LEVEL = 2)] = "GAME_ENTER_LEVEL"),
            (e[(e.GAME_UNLOCK_LEVEL = 3)] = "GAME_UNLOCK_LEVEL"),
            (e[(e.BANNER_SHOW = 4)] = "BANNER_SHOW"),
            (e[(e.BANNER_CLICK = 5)] = "BANNER_CLICK"),
            (e[(e.BANNER_CLOSE = 6)] = "BANNER_CLOSE"),
            (e[(e.INSERT_SHOW = 7)] = "INSERT_SHOW"),
            (e[(e.INSERT_CLICK = 8)] = "INSERT_CLICK"),
            (e[(e.INSERT_CLOSE = 9)] = "INSERT_CLOSE"),
            (e[(e.VIDEO_SHOW = 10)] = "VIDEO_SHOW"),
            (e[(e.VIDEO_CLOSE = 11)] = "VIDEO_CLOSE"),
            (e[(e.VIDER_CLICK = 12)] = "VIDER_CLICK"),
            (e[(e.NATIVE_SHOW = 13)] = "NATIVE_SHOW"),
            (e[(e.NATIVE_CLICK = 14)] = "NATIVE_CLICK"),
            (e[(e.NATIVE_CLOSE = 15)] = "NATIVE_CLOSE"),
            (e[(e.INIT = 16)] = "INIT");
    })(o.NodeAction || (o.NodeAction = {}));
var v = (function (e) {
    function t() {
        var t = e.call(this) || this;
        return (
            (t._type = 1),
            (t._config = {
                banner_ad_enbale: 1,
                icon_ad_enable: 0,
                inser_ad_delayed_probability: 0,
                inert_ad_enbale: 0,
                navite_ad_code: "",
                native_ad_enbable: 0,
                video_ad_enable: 0,
                banner_code: "a0b66bccd2e34622bc9a08d21084020a",
                video_ad_code: "d8b41a12d2bf42198d30d826d2978c72",
                boxPortalCode: "",
                enable: 1,
                flush_ad_time: -1,
                log_enable: 1,
                inser_ad_node: [],
                custom_ad_ebable: 1,
                custom_code: "2769a372bb954e039bab845d1f1fb2f5",
                inser_ad_delayed_show: 0,
                custom_ad_node: [
                    {id: 1, enable: 1, show_banner: 0, banner: {type: 5, x: 0, y: 0, top: !1, enable: 1}},
                    {id: 2, enable: 0, show_banner: 0, banner: {type: 5, x: 0, y: 0, top: !1, enable: 1}},
                    {id: 3, enable: 0, show_banner: 0, banner: {type: 5, x: 0, y: 0, top: !1, enable: 1}},
                    {id: 4, enable: 0, show_banner: 0, banner: {type: 5, x: 0, y: 0, top: !1, enable: 1}}
                ],
                custom_banner_request: "",
                treasure_chest_count: 15,
                show_lucky_box: 0,
                show_game_collection: 0,
                upload_statistics: 0
            }),
            (t._gameCode = null),
            (t._gameTime = 0),
            (t._clipboardData = null),
            (t._initCallbacks = null),
            (t.limitClick = 0),
            (t._random = -1),
            (t.fristGame = !1),
            (t._levelTime = 0),
            (t._isVivo = !1),
            (t._netInitCount = 0),
            (t._loading = !1),
            (t.ivKey = null),
            (t.gameID = 1),
            (t.sdkVersion = 2),
            (t.banner_bx_count = 0),
            (t.video_bx_count = 0),
            (t.video_click_count = 0),
            (t.inter_show_count = 0),
            (t.privacy = null),
            (t.treasureChestCount = 0),
            (t.allowConnectServer = !0),
            (t.showGameStarBoxCount = 0),
            (t.index = 0),
            t
        );
    }
    var o;
    return (
        __extends(t, e),
        (o = t),
        Object.defineProperty(t, "Instance", {
            get: function () {
                return null == o._instance && (o._instance = new o()), o._instance;
            },
            enumerable: !1,
            configurable: !0
        }),
        (t.prototype.initData = function () {
            if (
                (cc.sys.platform == cc.sys.VIVO_GAME && (this._isVivo = !0),
                console.log("当前平台： " + cc.sys.platform + " " + cc.sys.VIVO_GAME + " " + this._isVivo),
                (this._utils = s.default.instance),
                (this.privacy = new r.default()),
                this._isVivo)
            ) {
                _.default.Instance.onListenHome(),
                    _.default.Instance.init(),
                    (this._userId = _.default.Instance.getUserId()),
                    (this._source = _.default.Instance.getSource()),
                    console.log("this._source: ", this._source),
                    this._source.query.type,
                    (this.allowConnectServer = this.obtainConnectServer()),
                    console.log("this.allowConnectServer: ", this.allowConnectServer);
                var e = this;
                this._sysytemInfo = _.default.Instance.getSystemInfoSync();
                var t = this._sysytemInfo.miniGame.package;
                (this._gameCode = t.split(".")[2]),
                    _.default.Instance.getNetType(function (t) {
                        e._netType = t;
                    }),
                    console.log("设置隐私：", t.split(".")[1]),
                    (this.edType = "lingqu" == t.split(".")[1] ? c.EncryptType.ED_LQ : c.EncryptType.ED_CY),
                    console.log("this.edType: ", this.edType);
            }
        }),
        (t.prototype.obtainConnectServer = function () {
            var e = this._source.query.type;
            return (
                console.log("gameSource:", this._source.query.type),
                ("intent" != e && "shortcut" != e) ||
                    "ed9fb050cdcde057" == this._userId ||
                    "9e1e76a35fe7062f" == this._userId
            );
        }),
        (t.prototype.isPortrait = function () {
            return cc.winSize.width < cc.winSize.height;
        }),
        (t.prototype.startTime = function () {
            this._levelTime = new Date().getTime();
        }),
        (t.prototype.getSystemInfoSync = function () {
            return this._sysytemInfo;
        }),
        (t.prototype.endLevelTime = function (e) {
            var t = new Date().getTime() - this._levelTime;
            this.durationLog(Math.floor(t / 1e3), e);
        }),
        (t.prototype.requestConfig = function () {
            var e = this;
            if (this._isVivo)
                if (this.allowConnectServer) {
                    var t = this;
                    this._utils.log(t._netType),
                        this.onOk(this._config),
                        _.default.Instance.getClipboardData(function (o) {
                            t._clipboardData = o;
                            var n = y[e.edType],
                                i = {
                                    key: n,
                                    gameCode: t._gameCode,
                                    clipboard: o,
                                    manuId: t._type,
                                    openId: t._userId,
                                    source: JSON.stringify(t._source.query),
                                    platformVersionCode:
                                        null == t._sysytemInfo ? 0 : t._sysytemInfo.platformVersionCode,
                                    netType: t._netType,
                                    dateTime: new Date().getTime(),
                                    miniGame: t._sysytemInfo.miniGame,
                                    sdkVersion: t.sdkVersion
                                },
                                a = JSON.stringify(i);
                            e._utils.sendPost(["config", "config", "config"][t.edType], a, n, t.sdkVersion);
                        });
                } else this.onOk(this._config);
        }),
        (t.prototype.reportLog = function (e, t) {
            var o = this;
            if (this._isVivo && this.allowConnectServer && 0 != this._config.upload_statistics) {
                var n = this;
                _.default.Instance.getClipboardData(function (i) {
                    n._clipboardData = i;
                    var a = y[o.edType],
                        r = {
                            key: a,
                            gameCode: n._gameCode,
                            clipboard: i,
                            manuId: n._type,
                            openId: n._userId,
                            type: e,
                            content: t,
                            source: JSON.stringify(n._source.query),
                            dateTime: new Date().getTime(),
                            sdkVersion: n.sdkVersion
                        };
                    o._utils.sendPost(["adlog", "adlog", "adlog"][n.edType], JSON.stringify(r), a, n.sdkVersion);
                });
            }
        }),
        (t.prototype.durationLog = function (e, t) {
            if (
                (void 0 === t && (t = 0),
                this._isVivo && this.allowConnectServer && 0 != this._config.upload_statistics)
            ) {
                var o = -1;
                e > 0 && (o = this._random);
                var n = y[this.edType],
                    i = {
                        key: n,
                        gameCode: this._gameCode,
                        clipboard: this._clipboardData,
                        manuId: this._type,
                        openId: this._userId,
                        level: t,
                        seconds: e,
                        source: JSON.stringify(this._source.query),
                        random: o,
                        dateTime: new Date().getTime(),
                        sdkVersion: this.sdkVersion
                    };
                this._utils.sendPost(
                    ["duration", "duration", "duration"][this.edType],
                    JSON.stringify(i),
                    n,
                    this.sdkVersion
                );
            }
        }),
        (t.prototype.init = function (e, t) {
            var o = this;
            if (
                ((this._gameTime = new Date().getTime()),
                console.log("=============初始化sdk,获取当前时间： " + this._gameTime),
                (this.edType = t),
                this.initData(),
                (this._config.banner_code = e.banner_code),
                (this._config.video_ad_code = e.video_ad_code),
                (this._config.custom_code = e.custom_code),
                (this._config.boxPortalCode = e.boxPortalCode),
                console.log("=============init=========type： " + t),
                this._isVivo)
            ) {
                var n = this;
                this._random <= 0 && (this._random = this._utils.getRandomInt(0, 1e4)),
                    this._utils.addListener(this),
                    this.requestConfig(),
                    this._utils.log("********用户退出游戏或退到后台_gameTime： " + n._gameTime),
                    _.default.Instance.onHide(function () {
                        var e = new Date().getTime() - n._gameTime;
                        o._utils.log("********用户退出游戏或退到后台time： " + e);
                        var t = Math.floor(e / 1e3);
                        o._utils.log("********gameTime " + t), n.durationLog(t, 0), (n._gameTime = 0);
                    }),
                    _.default.Instance.onShow(function () {
                        (n._gameTime = new Date().getTime()),
                            o._utils.log("*******用户回到游戏,当前游戏时间：" + n._gameTime);
                    });
            } else console.log("=============当前不是vivo平台type： " + t);
        }),
        (t.prototype.flushConfig = function () {
            if (this._isVivo) {
                var e = this,
                    t = function () {
                        if (e._loading) e.unschedule(t);
                        else {
                            if (e._netInitCount > 2) return e._utils.ok(null), void e.unschedule(t);
                            e._netInitCount++, e.requestConfig();
                        }
                    };
                this.schedule(t, 10);
            }
        }),
        (t.prototype.onOk = function (e) {
            var t = this;
            if ((console.log("--------------onOk---------------"), this._isVivo)) {
                (this._config = e),
                    (o.Instance.banner_bx_count = this._config.banner_ad_enbale),
                    (o.Instance.video_bx_count = this._config.video_ad_enable),
                    (o.Instance.inter_show_count = this._config.inert_ad_enbale);
                var n = this;
                this._config
                    ? ((this._loading = !0),
                      _.default.Instance.initConfig(this._config, function () {
                          if ((n._initCallbacks && n._initCallbacks(!0), !(t._config.flush_ad_time <= 0))) {
                              var e = function () {
                                  n.scheduleOnce(function () {
                                      n.showInterstitial(h.InterstitialType.INTERSTITIAL_GAME_OVER), e();
                                  }, t._config.flush_ad_time);
                              };
                              e();
                          }
                      }))
                    : (n._utils.log("********* initConfig is faill : " + JSON.stringify(this._config)),
                      n._initCallbacks && !this._loading && (n._initCallbacks(!1), this.flushConfig()));
            }
        }),
        (t.prototype.showBanner = function (e, t, o, n, i) {
            void 0 === e && (e = p.BannerType.BOTTOM_CENTER),
                void 0 === t && (t = f.NativeType.BANNER),
                void 0 === o && (o = !1),
                void 0 === n && (n = 0),
                void 0 === i && (i = 0),
                this._isVivo &&
                    (this.isPortrait() || 1 == cc.sys.localStorage.getItem("privacy")) &&
                    _.default.Instance.showBanner(e, t, o, n, i);
        }),
        (t.prototype.showBannerNode = function (e) {
            var t = cc.view.getVisibleSize();
            (e.active = !0),
                _.default.Instance.showBanner(
                    p.BannerType.BOTTOM_CENTER,
                    f.NativeType.BANNER_NO_NATIVE,
                    !1,
                    0,
                    0,
                    function () {
                        e.setPosition(cc.v2(e.x, -(t.height / 2 - (e.height + 100))));
                    }
                );
        }),
        (t.prototype.hideBanner = function () {
            this._isVivo && _.default.Instance.hideBanner();
        }),
        (t.prototype.hideIcon = function () {
            this._isVivo && _.default.Instance.hideIcon();
        }),
        (t.prototype.showInterstitial = function (e) {
            void 0 === e && (e = h.InterstitialType.INTERSTITIAL_GAME_OVER),
                console.log("SDK调用了showInterstitial"),
                this._isVivo && (_.default.Instance.hideBanner(), _.default.Instance.showInterstitial(e));
        }),
        (t.prototype.showIconAd = function (e, t, o) {
            void 0 === o && (o = 0), this._isVivo && (this.hideIcon(), _.default.Instance.showIconAd(o, e, t));
        }),
        (t.prototype.showRewardVideo = function (e, t, o) {
            this._isVivo ? _.default.Instance.showRewardVideo(e, t, o) : e();
        }),
        (t.prototype.showToast = function (e) {
            this._isVivo && _.default.Instance && _.default.Instance.showToast(e);
        }),
        (t.prototype.showBoxVideoAndBanner = function (e, t) {
            var n = cc.view.getVisibleSize();
            (e.active = !0),
                e.setPosition(cc.v2(e.x, -(n.height / 2 - (e.height + 100)))),
                this._config &&
                    this._config.banner_ad_enbale > 0 &&
                    (console.log("=====难道没来这里"), e.setPosition(cc.v2(e.x, -(n.height / 2 - e.height / 2)))),
                o.Instance.showBoxVideo(
                    function (e, o) {
                        t && t(e, o);
                    },
                    function () {
                        o.Instance.showBannerNode(e);
                    }
                );
        }),
        (t.prototype.showGetUICoinBox = function (e, t, n, i, a) {
            var r = this;
            if (
                (void 0 === t && (t = null),
                void 0 === n && (n = 0),
                void 0 === i && (i = 0),
                void 0 === a && (a = u.CoinBoxType.BIG),
                console.log(
                    "this.treasureChestCount: " + this.treasureChestCount + " this._config.show_lucky_box : ",
                    this._config.show_lucky_box
                ),
                console.log("boxType = ", a),
                this.treasureChestCount == this._config.treasure_chest_count - 1 ||
                    (1 != this.showGameStarBoxCount && 1 == i) ||
                    2 == i)
            ) {
                o.Instance.showGameCollection(),
                    a == u.CoinBoxType.BIG && 0 == this._config.show_lucky_box && (a = u.CoinBoxType.TWINS);
                var s = this;
                d.TreasureChestBox.Instance.cratorUIGetCoinBox(
                    l.TreasureChestType.NINE,
                    e,
                    function () {
                        (s.treasureChestCount = 0), 1 == i && (r.showGameStarBoxCount = 1), t && t();
                    },
                    n,
                    a
                );
            } else (this.treasureChestCount += 1), t && t();
        }),
        (t.prototype.showBoxVideo = function (e, t, n) {
            void 0 === t && (t = null),
                void 0 === n && (n = 0),
                console.log("当前游戏的 gameID：", n),
                (o.Instance.video_bx_count = 100),
                o.Instance.video_bx_count > 0 &&
                    ((o.Instance.video_bx_count -= 1),
                    d.TreasureChestBox.Instance.cratorTreasureChest(l.TreasureChestType.NINE, e, t, n));
        }),
        (t.prototype.showBoxPortalAd = function (e) {
            this._isVivo && _.default.Instance.showboxPortalAd(e);
        }),
        (t.prototype.showBoxBanner = function () {
            this._isVivo && _.default.Instance.showBoxBanner();
        }),
        (t.prototype.hideBoxBanner = function () {
            this._isVivo && _.default.Instance.hideBoxBanner();
        }),
        (t.prototype.hideBoxPortalAd = function () {
            this._isVivo && _.default.Instance.hideBoxPortalAd();
        }),
        (t.prototype.hideInterstitial = function () {
            _.default.Instance.hideInterstitial();
        }),
        (t.prototype.showPrivacy = function (e) {
            return
            void 0 === e && (e = !0), this.privacy && this.privacy.showPrivacy(this.edType, e);
        }),
        (t.prototype.vibrateShort = function () {
            this._isVivo && _.default.Instance.vibrateShort();
        }),
        (t.prototype.closeGame = function () {
            var e = window.qg;
            e && e.exitApplication();
        }),
        (t.prototype.getGameCode = function () {
            return this._gameCode;
        }),
        (t.prototype.getServerTreasureChestCount = function () {
            return this._config.treasure_chest_count;
        }),
        (t.prototype.showGameCollection = function () {
            return 1 == this._config.show_game_collection;
        }),
        (t._instance = null),
        (o = __decorate([g], t))
    );
})(cc.Component);
(o.default = v), (cc.SDK = v.Instance);
